package in.abip.chisame;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

public class UdpTelnetClient implements ITelnetClient {
	private DatagramSocket _datagramSocket = null;
	private DatagramPacket _datagramPacket = null;
	private InetAddress _inetAddress = null;
	private int _port = 6667;

	public Boolean connect(String host, int port) {
		try {
			_datagramSocket = new DatagramSocket();
		} catch (SocketException e) {
			return false;
		}
		try {
			_inetAddress = InetAddress.getByName(host);
		} catch (UnknownHostException e) {
			return false;
		}
		return true;
	}

	public void disconnect() {
		_datagramSocket.close();

	}

	public String attention(String command) {
		byte[] data;
		data = new byte[1024];
		data = command.getBytes();
		_datagramPacket = new DatagramPacket(data, data.length, _inetAddress,
				_port);
		try {
			_datagramSocket.send(_datagramPacket);
		} catch (IOException e) {
		}
		return null;
	}

}
